﻿
//----------------------------------------------------------------------------------
// Include
//----------------------------------------------------------------------------------
#include "Effekseer.DefaultEffectLoader.h"
#include "../Effekseer.h"
#include <memory>

//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
namespace Effekseer
{
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
DefaultEffectLoader::DefaultEffectLoader(FileInterface* fileInterface)
	: m_fileInterface(fileInterface)
{
	if (m_fileInterface == NULL)
	{
		m_fileInterface = &m_defaultFileInterface;
	}
}

//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
DefaultEffectLoader::~DefaultEffectLoader()
{
}

//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
bool DefaultEffectLoader::Load(const EFK_CHAR* path, void*& data, int32_t& size)
{
	assert(path != NULL);

	data = NULL;
	size = 0;

	std::unique_ptr<FileReader> reader(m_fileInterface->OpenRead(path));
	if (reader.get() == NULL)
		return false;

	size = (int32_t)reader->GetLength();
	data = new uint8_t[size];
	reader->Read(data, size);

	return true;
}

//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
void DefaultEffectLoader::Unload(void* data, int32_t size)
{
	uint8_t* data8 = (uint8_t*)data;
	ES_SAFE_DELETE_ARRAY(data8);
}

//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
} // namespace Effekseer
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
